/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edi.entities;

import edi.entities.enums.DocPermission;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.Where;
import org.joda.time.DateTime;
import org.springframework.data.domain.Auditable;

/**
 *
 * @author Kamil
 */
@Entity
@Table(name = "T_DEP_USR_DOC")
@Where(clause="DUD_AUDIT_RD is null")
@NamedQueries({
    @NamedQuery(name = "DepUsrDoc.findByDocId", query = "SELECT p FROM DepUsrDocEntity p WHERE p.dudDocument = :dudDocument"),
    @NamedQuery(name = "DepUsrDoc.findAllByDocId", query = "SELECT p FROM DepUsrDocEntity p WHERE p.dudDocument in (:dudDocument)")})

public class DepUsrDocEntity implements Auditable<Long, Long>, Serializable {

    private static final long serialVersionUID = 4169905761802955798L;

    @Id
    @SequenceGenerator(name = "dep_usr_doc_sequence", sequenceName = "S_DUD_ID", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "dep_usr_doc_sequence")
    @Column(name = "DUD_ID")
    private Long dudId;

    @ManyToOne()
    @JoinColumn(name = "DUD_UDE_ID", referencedColumnName = "UDE_ID", nullable = false)
    private DepartmentUserEntity dudDepartmentUser;
       
    @ManyToOne()
    @JoinColumn(name = "DUD_DOC_ID", referencedColumnName = "DOC_ID", nullable = false)
    private DocumentEntity dudDocument;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "DUD_PERMISSION", length = 10, nullable = false)
    private DocPermission dudPermission;
    
    
    @Column(name = "DUD_AUDIT_CD") 
    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")    
    private DateTime createdDate;
    
    @Column(name = "DUD_AUDIT_CU")
    private Long createUser;
    
    @Column(name = "DUD_AUDIT_MD")
    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")    
    private DateTime modifiedDate;
    
    @Column(name = "DUD_AUDIT_MU")
    private Long modifiedUser;
    
    @Column(name = "DUD_AUDIT_RD")
    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")    
    @SuppressWarnings("unused")
    private DateTime removeDate;
    
    @Column(name = "DUD_AUDIT_RU")
    @SuppressWarnings("unused")
    private Long removeUser;

    
    @Override
    public boolean isNew() {
        return (dudId == null);
    }

    public Long getDudId() {
        return dudId;
    }

    public void setDudId(Long dudId) {
        this.dudId = dudId;
    }

    public DepartmentUserEntity getDudDepartmentUser() {
        return dudDepartmentUser;
    }

    public void setDudDepartmentUser(DepartmentUserEntity dudDepartmentUser) {
        this.dudDepartmentUser = dudDepartmentUser;
    }

    public DocumentEntity getDudDocument() {
        return dudDocument;
    }

    public void setDudDocument(DocumentEntity dudDocument) {
        this.dudDocument = dudDocument;
    }

    public DocPermission getDudPermission() {
        return dudPermission;
    }

    public void setDudPermission(DocPermission dudPermission) {
        this.dudPermission = dudPermission;
    }
      
     @Override
     public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
     }

     @Override
     public boolean equals(Object o) {
        return EqualsBuilder.reflectionEquals(this, o);
     }

     @Override
     public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
     }
     
    
    @Override
    public Long getId() {
        return dudId;
    }
    
        @Override
    public Long getCreatedBy() {
      return createUser;
    }
    
    @Override
    public void setCreatedBy(Long u) {
        createUser = u;
    }

    @Override
    public org.joda.time.DateTime getCreatedDate() {
    return createdDate;
    }

    @Override
    public void setCreatedDate(org.joda.time.DateTime dt) {
       createdDate = dt;
    }

    @Override
    public Long getLastModifiedBy() {
        return modifiedUser;
    }

    @Override
    public void setLastModifiedBy(Long u) {
       modifiedUser = u;
    }

    @Override
    public org.joda.time.DateTime getLastModifiedDate() {
        return modifiedDate;
    }

    @Override
    public void setLastModifiedDate(org.joda.time.DateTime dt) {
        modifiedDate = dt;
    }
    
    public void setRemoveDate(org.joda.time.DateTime dt) {
        removeDate = dt;
    }
           
    public void setRemovedBy(Long u) {
       removeUser = u;
    }
    
}
